//
//  PGTopicViewController.m
//  PhotographicGuide
//
//  Created by indream on 13-4-12.
//  Copyright (c) 2013年 indream. All rights reserved.
//

#import "PGTopicViewController.h"
#import "MobClick.h"

static NSString* NOTIFICATION_TOPIC_TABLE_REFRESH = @"__NOTIFICATION_TOPIC_TABLE_REFRESH__";

@interface PGTopicViewController ()

@end

@implementation PGTopicViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
    self.shareView.isDetail = NO;
    self.tableViewController = [[PGTopicListTableViewController alloc]init];
    self.tableViewController.tag = self.tag;
    self.tableViewController.navigationController = self.navigationController;

    [self.listView addSubview:self.tableViewController.tableView];
    self.tableViewController.tableView.backgroundColor = [UIColor clearColor];
    CGRect rect = self.listView.frame;
    rect.origin.x = 0.0;
    rect.origin.y = 0.0;
    self.tableViewController.tableView.frame =  rect;
    self.tableViewController.tableView.hidden = NO;
    NSArray *titles = [self.title componentsSeparatedByString:@" | "];
    self.titleLabel.text = titles.count>1?[titles objectAtIndex:0]:self.title;
    [self.activityIndicatorView startAnimating];
    UISwipeGestureRecognizer *swiper = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeHandle:)];
    [self.view addGestureRecognizer:swiper];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideActivity:) name:NOTIFICATION_TOPIC_TABLE_REFRESH object:nil];
}
-(void)swipeHandle:(UISwipeGestureRecognizer*)gesture{
    if(gesture.direction==UISwipeGestureRecognizerDirectionRight){
        [self backHandle:nil];
    }
}
-(void)hideActivity:(NSNotification*)notification{
    NSLog(@"hide activity!!!");
    [self.activityIndicatorView stopAnimating];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:[NSString stringWithFormat:@"topic=%@",self.title]];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:[NSString stringWithFormat:@"topic=%@",self.title]];
}
- (void)viewDidUnload {
    [self setTitleLabel:nil];
    [super viewDidUnload];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:NOTIFICATION_TOPIC_TABLE_REFRESH object:nil];

}
- (IBAction)backHandle:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
